@{
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    <div>
        @item.PropertyDescriptors["ImageUrl"].DisplayName</div>
    <div style="margin-top: 5px;">
    <table>
    <tr><td>   @(Ajax.Dna().TextBox(item.GenerateFieldID("ImageUrl"))
                .Value(item.UserPreferences["ImageUrl"] != null ? item.GetString("ImageUrl") : "http://")
                .GetHtml()
            )</td>
    <td>
    @Ajax.Dna().Button(item.GenerateFieldID("btnBrowseIcon")).LocText("RES_BROWSE").Click("$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",$(\"#" + item.GenerateFieldID("ImageUrl") + "\"));").ImageIcons(Url.Content("~/content/images/icon_folder_open_16.gif")).GetHtml()
    </td>
    </tr>
    </table>
     
    </div>
    <div style="margin-top: 5px;">@item.PropertyDescriptors["LinkUrl"].DisplayName</div>
    <div>
        @(
            Ajax.Dna().TextBox(item.GenerateFieldID("LinkUrl"))
                .Value(item.UserPreferences["LinkUrl"] != null ? item.GetString("LinkUrl") : "")
                .GetHtml()
        )
    </div>
    <div style="margin-top: 5px;">
        @item.PropertyDescriptors["Alignment"].DisplayName</div>
    <div>
        @(
            Ajax.Dna().ComboBox(item.GenerateFieldID("Alignment"))
                .DropDownStyle(DropdownStyles.DropdownList)
                .Width(100)
                .Items(items =>
           {
               items.AddValue(Html.Global("RES_ALIGN_CENTER"), "center");
               items.AddValue(Html.Global("RES_ALIGN_LEFT"), "left");
               items.AddValue(Html.Global("RES_ALIGN_RIGHT"), "right");
           })
           .Select(item.UserPreferences["Alignment"] != null ? item.GetString("Alignment") : "center")
           .GetHtml()
           )
    </div>
    <div style="margin-top: 5px;">
        @item.PropertyDescriptors["Target"].DisplayName</div>
    <div>
        @(
            Ajax.Dna().ComboBox(item.GenerateFieldID("Target"))
                .Width(150)
                .Items(items =>
                {
                    items.AddValue(Html.Global("RES_TARGET_BLANK"), "_blank");
                    items.AddValue(Html.Global("RES_TARGET_PARENT"), "_parent");
                    items.AddValue(Html.Global("RES_TARGET_SELF"), "_self");
                    items.AddValue(Html.Global("RES_TARGET_TOP"), "_top");
                })
                .Select(item.UserPreferences["Target"] == null ? "_self" : (!string.IsNullOrEmpty(item.UserPreferences["Target"].ToString())) ? item.UserPreferences["Target"].ToString() : "_self")
               .GetHtml()
               )
    </div>
    <div style="margin-top: 5px;">
        @item.PropertyDescriptors["ImageWidth"].DisplayName
    </div>
    <div>
        @(
            Ajax.Dna().TextBox(item.GenerateFieldID("ImageWidth"))
                .NumericOnly()
                .Value(item.UserPreferences["ImageWidth"] != null ? item.GetInt("ImageWidth") : 0)
                .GetHtml()
        )
    </div>
    <div style="margin-top: 5px;">
        @item.PropertyDescriptors["ImageHeight"].DisplayName
    </div>
    <div>
        @(
            Ajax.Dna().TextBox(item.GenerateFieldID("ImageHeight"))
                .NumericOnly()
                .Value(item.UserPreferences["ImageHeight"] != null ? item.GetInt("ImageHeight") : 0)
                .GetHtml()
        )
    </div>
    </text>)
        .Content(@<text>
    @{
        var _align = item.UserPreferences["Alignment"] != null ? item.UserPreferences["Alignment"].ToString() : "center";
        var _target = item.UserPreferences["Target"] == null ? "_self" : (!string.IsNullOrEmpty(item.UserPreferences["Target"].ToString())) ? item.UserPreferences["Target"].ToString() : "_self";

    }
    @if (!string.IsNullOrEmpty(item.GetString("ImageUrl")))
    {
        if ((item.GetInt("ImageHeight") > 0) && (item.Model != null))
        {
            Html.RegisterStartupScript(" $(\".d-item-body\",$(\"#" + item.Model.ID.ToString() + "\")).css({height:\"" + item.UserPreferences["ImageHeight"].ToString() + "px\"});");
        }
        
        <div class="ui-helper-reset" style="padding:0px;margin:0px;text-align:@_align">
            @if ((item.UserPreferences["LinkUrl"] != null) && (!String.IsNullOrEmpty(item.UserPreferences["LinkUrl"].ToString())))
            { 
                <a href="@item.UserPreferences["LinkUrl"].ToString()" target="@_target">
                    @Html.Image(item.UserPreferences["ImageUrl"].ToString(), item.GetInt("ImageWidth"), item.GetInt("ImageHeight"))
                </a>
            }
            else
            {
                @Html.Image(item.UserPreferences["ImageUrl"].ToString(), item.GetInt("ImageWidth"), item.GetInt("ImageHeight"))
            }
        </div>
    }
    else
    {
        if ((HttpContext.Current.Request.IsAuthenticated) && (HttpContext.Current.User.IsWebOwner()))
        { 
        <div  style="padding: 15px; margin-top: 5px;">
            Please add an image link first.
        </div>
        }
    }
    </text>)
        .Render();
}
